package com.hongning.railway.ui.dynamic_photo;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hongning.railway.R;
import com.hongning.railway.app.Constant;
import com.hongning.railway.databinding.FragmentDynamicphotepreviewBinding;
import com.hongning.railway.entity.resbean.ResPhotoItem;
import com.hongning.railway.util.GlideUtils;
import com.zhouwei.mzbanner.MZBannerView;
import com.zhouwei.mzbanner.holder.MZHolderCreator;
import com.zhouwei.mzbanner.holder.MZViewHolder;

import java.util.List;

import me.goldze.mvvmhabit.BR;
import me.goldze.mvvmhabit.base.BaseFragment;
import me.goldze.mvvmhabit.base.BaseViewModel;

public class DynamicPhotoPreViewFragment extends BaseFragment<FragmentDynamicphotepreviewBinding, BaseViewModel> {
    List<ResPhotoItem> datas;
    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_dynamicphotepreview;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initParam() {
        super.initParam();
        datas = getArguments().getParcelableArrayList(Constant.EXTRA_DATA);
    }

    @Override
    public void initData() {
        super.initData();
        if (datas!=null){
            binding.mzBanner.setPages(datas, new MZHolderCreator() {
                @Override
                public MZViewHolder createViewHolder() {
                    return new BannerViewHolder();
                }
            });

        }
    }

    public class BannerViewHolder implements MZViewHolder<ResPhotoItem> {
        View rootview;
        ImageView imageView;
        TextView textView;
        @Override
        public View createView(Context context) {
            rootview= LayoutInflater.from(context).inflate(R.layout.item_bigphoto_preview,null,false);
            imageView=rootview.findViewById(R.id.iv_img);
            textView = rootview.findViewById(R.id.tv_content);
            return rootview;
        }

        @Override
        public void onBind(Context context, int i, ResPhotoItem resPhotoItem) {
            if (!TextUtils.isEmpty(resPhotoItem.getPhotoContent())){
                textView.setText(resPhotoItem.getPhotoContent());
            }
            GlideUtils.loadImageView(context,resPhotoItem.getPhotoLabel(),imageView);
        }
    }
}
